package com.em.tuppence.core.model.application;

import java.util.Date;

/**
 * This is the base class for tokens.  A token is the software representation of an answer generator.  This
 * is like a so called "key-fob" in the real world.  When a token is provisioned its values are kept within
 * this class so that the answer verifier can use the guess sent by a user to check against the token that
 * generated the guess.
 * 
 * the verifier can also handle things like locking the token and such.  attempts and attempt logging are outside
 * of the scope of this class
 * 
 * @author chris
 *
 */
public abstract class AbstractToken {

	/**
	 * the secret used in the TOTP (Time-based one password at a time) algorithm 
	 * 
	 * this can be generated or provided from a device (iOS or Android)
	 */
	private byte[] secret = null;
	
	/**
	 * the id of the secret so that it can be looked up
	 */
	private String id = null;
	
	/**
	 * identifies the token (unique within the set of a single user's tijebs)
	 */
	private String name = null;
	
	/**
	 * describes the token
	 */
	private String description = null;
	
	/**
	 * how often the token is regenerated or how long it is good for.
	 * 
	 * different token types will default to different values but this will be used for resolving that block of time.
	 */
	private int goodForSeconds = 60;
	
	/**
	 * how long to lock the token if too many attempts are made
	 */
	private int lockoutSeconds = 600;
	
	/**
	 * how many attempts to allow before locking out the token (see lockoutSeconds)
	 * 
	 * a value of -1 (negative one) means unlimited attempts
	 */
	private int allowedAttempts = -1;
	
	/**
	 * is this token asynchronous?
	 * 
	 *  email, sms, and other token that require two-way communication are asynchronous.  they require
	 *  that the server communicate to the user the answer value over some other medium (again: email, sms)
	 */
	private boolean isAsynchronous = false;
	
	/**
	 * how many digits the generated answer is (how many digits are communicated or expected)
	 */
	private int generatedSize = 8;

	/**
	 * when the token was generated
	 */
	private Date createdDate = null;
	
	public byte[] getSecret() {
		return secret;
	}

	public void setSecret(byte[] secret) {
		this.secret = secret;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getGoodForSeconds() {
		return goodForSeconds;
	}

	public void setGoodForSeconds(int goodForSeconds) {
		this.goodForSeconds = goodForSeconds;
	}

	public int getLockoutSeconds() {
		return lockoutSeconds;
	}

	public void setLockoutSeconds(int lockoutSeconds) {
		this.lockoutSeconds = lockoutSeconds;
	}

	public int getAllowedAttempts() {
		return allowedAttempts;
	}

	public void setAllowedAttempts(int allowedAttempts) {
		this.allowedAttempts = allowedAttempts;
	}

	public boolean isAsynchronous() {
		return isAsynchronous;
	}

	public void setAsynchronous(boolean isAsynchronous) {
		this.isAsynchronous = isAsynchronous;
	}

	public int getGeneratedSize() {
		return generatedSize;
	}

	public void setGeneratedSize(int generatedSize) {
		this.generatedSize = generatedSize;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	} 	
	
}
